package suites {
	import suites.stub.PageStub;

	import org.splink.deepsplink.boot.IBootStrategy;

	/**
	 * @author Max Kugland
	 */
	public class AbstractConfig {
		public static const MOCK_PAGE_CP : String = "suites.stub.PageStub";		public static const MOCK_PAGE_CLASS : Class = PageStub;		public static const PAGE_TITLE : String = "Page ";		public static const ROOT : String = "root";		public static const HOME : String = "1";		public static const P_404 : String = "404";

		final protected function get minXml() : XML { 
			return <config eagerPages="true">
					<page id={ROOT} clazz={MOCK_PAGE_CP} title={PAGE_TITLE + ROOT} request="hide-initshow-finalize">
						<page id={P_404} clazz={MOCK_PAGE_CP} title={PAGE_TITLE + P_404} />
						<page id={count} clazz={MOCK_PAGE_CP} title={PAGE_TITLE + pageCount} />
					</page>
					<home id={HOME} />
					<notfound redirect={P_404} />
				</config>;
		}

		final protected function get standardXml() : XML { 
			return <config eagerPages="true">
					<page id={ROOT} clazz={MOCK_PAGE_CP} title={PAGE_TITLE + ROOT} request="hide-initshow-finalize">
						<page id={P_404} clazz={MOCK_PAGE_CP} title={PAGE_TITLE + P_404} />
						<page id={count} clazz={MOCK_PAGE_CP} title={PAGE_TITLE + pageCount} />
						<page id={count} clazz={MOCK_PAGE_CP} title={PAGE_TITLE + pageCount}>
							<page id={count} clazz={MOCK_PAGE_CP} title={PAGE_TITLE + pageCount}>
								<page id={count} clazz={MOCK_PAGE_CP} title={PAGE_TITLE + pageCount} />
							</page>
							<page id={count} clazz={MOCK_PAGE_CP} title={PAGE_TITLE + pageCount} />
						</page>
					</page>
					<home id={HOME} />
					<notfound redirect={P_404} />
				</config>;
		}

		private var _count : int = 0;

		final protected function get count() : int {
			_count++;
			return _count;
		}
		
		final protected function get pageCount() : uint {
			return _count;
		}

		[Before]
		public function before() : void {
			_count = 0;
		}

		final protected function createBootStrategy(fnc:Function, count : uint) : IBootStrategy {
			return new BootStrategy(fnc, count);
		}

		
	}
}

import suites.AbstractConfig;

import org.flexunit.asserts.assertEquals;
import org.flexunit.asserts.assertNotNull;
import org.splink.deepsplink.boot.IBootStrategy;
import org.splink.deepsplink.boot.IDeepsplinkFacade;
import org.splink.library.tree.Tree;

internal class BootStrategy implements IBootStrategy {
	private var _fnc : Function;
	private var _max : uint;

	public function BootStrategy(fnc : Function, max : uint) {
		_fnc = fnc;
		_max = max;
	}
	
	/**
	 * @inheritDoc
	 */
	public function boot(facade : IDeepsplinkFacade) : void {
		assertNotNull(facade.config);
		assertNotNull(facade.display);
		assertNotNull(facade.navigationCommand);
		assertNotNull(facade.tree);
		assertEquals(AbstractConfig.ROOT, facade.tree.root.id);
		assertEquals(AbstractConfig.HOME, facade.config.homeData.id);		assertEquals(AbstractConfig.P_404, facade.config.notfoundData.redirect);
		assertEquals(AbstractConfig.P_404, Tree.getNodeById(AbstractConfig.P_404, facade.tree.root).id);
		
		var first : int = 1;
		for (var i : int = first;i < _max;i++) {
			assertEquals(i.toString(), Tree.getNodeById(i.toString(), facade.tree.root).id);
		}
		
		assertEquals(first, facade.config.homeData.id);
		
		_fnc(facade);
	}
}